<template>
  <el-dialog :visible.sync="visible" v-dialogDrag :title="title" :close-on-click-modal="false" class="tl-dialog" width="1200px" @open="open" @close="close">
    <el-form class="tl-form" ref="form" :model="model" :rules="rules" label-width="150px" :disabled="disableEditSubmit">
			<el-row>
				<el-col :span="12">
					<el-form-item label="部门统称" prop="deptcommoncode" :rules="rules.validateRequire" label-width="180px">
						<el-select v-model="model.deptcommoncode" filterable clearable>
							<el-option v-for="item in codeModel.deptcommoncodeList" :key="item.code" :label="item.name" :value="item.code" />
						</el-select>
					</el-form-item>
				</el-col>
			</el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="岗位" prop="postcode" :rules="rules.validateRequire" label-width="180px">
            <el-select v-model="model.postcode" filterable clearable>
              <el-option v-for="item in codeModel.postcodeList" :key="item.code" :label="item.name" :value="item.code"  :disabled="originPostInfo.postcode === item.code"/>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button :type="disableEditSubmit === false ? 'text' : 'primary'" @click="doCancelEdit">取消</el-button>
      <el-button type="primary" @click="handOver" :loading="saveLoading" v-if="disableEditSubmit === false">确认</el-button>
    </div>
  </el-dialog>
</template>

<script>
/** mixins */
import { mixin_edit } from '@tapui/mixins/mixin_edit'
/** 子组件 */
/** 工具类 */
import { putAction, getAction, postAction, deleteAction } from '@tapui/utils/http'
/** VUE配置 */
export default {
  mixins: [mixin_edit],
  components: { },
  props: {
      originPostInfo: {
          type: Object,
          default: () => {
              return {}
          }
      }
  },
  data() {
    return {
      moduleTitle: '请选择要交接的岗位',
      urlPrefix: '/mms/postAuthorizationInfo/',
      url: {
        // 额外的url
          handover: "handover"
      }
    }
  },
  methods: {
      open() {
          this.title = this.moduleTitle
          this.$set(this.model, 'deptcommoncode', this.originPostInfo.deptcommoncode)
          this.$set(this.model, 'origindeptcommoncode', this.originPostInfo.deptcommoncode)
          this.$set(this.model, 'originpostcode', this.originPostInfo.postcode)
      },
      handOver() {
          this.saveLoading = true
          // 增加唯一单号
          postAction(this.urlPrefix + this.url.handover + '?billuid=' + this.uid, this.model)
              .then((res) => {
                  if (res.success) {
                      this.$tap.message(res.message, 'success')
                      this.visible = false
                      this.$emit('refresh')
                  } else {
                      this.$tap.alert(res.message, 'warning')
                  }
                  this.afterSubmit()
                  this.saveLoading = false
              })
              .catch((err) => {
                  this.saveLoading = false
              })
      }
  }
}
</script>

